<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <img src="img/timg1.jpg" id="img1">
    <input type="button" onclick="start()" value="切换图片">
    <input type="button" onclick="off()" value="停止切换" >
<script type="text/javascript">
    var x;
    function start() {
        var c= document.getElementById("img1")
        var d=1;
        if (!x) {
            x = setInterval(function () {
                if (d > 1) {
                    d = 0
                }
                d++
                console.log(d)
                c.src = "img/timg" + d + ".jpg"
            }, 1000)
        }
    }
    function off() {
     clearInterval(x)
    }
</script>
</body>
</html>